﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/

using System;
using ISC.MapDotNetServer.Common.Maps;

namespace OI.Framework
{
    public class DynamicLabelingItem
    {
        public bool IsSupported { get; set; }
        public double MinZoomLevel { get; set; }
        public string PrimaryKeyColName { get; set; }
        public string LabelTextColName { get; set; }


        // parses attributes out of layer
        public static DynamicLabelingItem ParseDynamicLabelingItem(Layer layer)
        {
            var item = new DynamicLabelingItem();

            if (layer != null && 
                layer.HasDynamicLabeling())
            {
                string[] dmArray = layer.GetDynamicLabelingString().Split(',');
                if (dmArray.Length == 3)
                {
                    item.IsSupported = true;
                    item.PrimaryKeyColName= dmArray[0];
                    item.LabelTextColName = dmArray[1];
                    item.MinZoomLevel = Convert.ToDouble(dmArray[2]);
                }
            }
            return item;
        }


        // serialize filter items
        public static string SerialzeDensityMapItem(DynamicLabelingItem item)
        {
            return item.PrimaryKeyColName + "," + item.LabelTextColName + "," + item.MinZoomLevel;
        }
    }
}
